package gui.panels.statistics;

import java.awt.Color;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.RectangleInsets;

public class SuccessPiePanel extends JPanel implements StatisticsContent {

    private static final long serialVersionUID = 1L;

    private int succesfulGuesses;
    private int totalGuesses;
    
    public SuccessPiePanel(int succesfulGuess, int totalGuess) {

        this.succesfulGuesses = succesfulGuess;
        this.totalGuesses = totalGuess;
        
        setBackground(Color.WHITE);
        
        DefaultPieDataset dataset = new DefaultPieDataset();
        dataset.setValue("Sucessful guesses", this.succesfulGuesses);
        dataset.setValue("Failed guesses", this.totalGuesses-this.succesfulGuesses);
        
        JFreeChart chart = ChartFactory.createPieChart3D(null, dataset, true,true,false);
        PiePlot3D piePlot = (PiePlot3D)(chart.getPlot());
        piePlot.setLabelLinksVisible(false);
        piePlot.setMaximumLabelWidth(0);
        piePlot.setInsets(new RectangleInsets(20, 20, 20, 20));
        piePlot.setOutlineVisible(false);
        piePlot.setBackgroundPaint(Color.WHITE);
        
        ChartPanel panel = new ChartPanel(chart);
        add(panel);
        setVisible(true);
    }

    @Override
    public String getTitle() {
        return "Success Pie";
    }

    @Override
    public JPanel getContent() {
        return this;
    }

    @Override
    public String getIconName() {
        return "Pie_chart.png";
    }
    
}
